<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:WpfFundamentals.Controls">


    <Style TargetType="{x:Type controls:SpinningControl}">
        <Setter Property="Focusable"
                Value="False"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:SpinningControl}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="rotateStoryboard">
                            <DoubleAnimation AutoReverse="False"
                                             RepeatBehavior="Forever"
                                             Duration="0:0:0.75"
                                             Storyboard.TargetName="aniElement"
                                             Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
                                             From="0.0"
                                             To="360.0"></DoubleAnimation>
                        </Storyboard>

                        <LinearGradientBrush x:Key="overlayBrush"
                                             EndPoint="0.5,1"
                                             StartPoint="0.5,0">
                            <GradientStop Color="Transparent"
                                          Offset="0" />
                            <GradientStop Color="#600000FF"
                                          Offset="0.5" />
                            <GradientStop Color="Transparent"
                                          Offset="1" />
                        </LinearGradientBrush>
                    </ControlTemplate.Resources>
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">

                        <Grid RenderTransformOrigin="0.5,0.5"
                              Name="aniElement">
                            <Ellipse Width="{TemplateBinding ActualWidth}"
                                     Height="{TemplateBinding ActualHeight}"
                                     Stroke="{StaticResource TurquoiseAliceBlueGradientBrush}"
                                     StrokeThickness="3">
                            </Ellipse>

                            <Ellipse Width="{TemplateBinding ActualWidth}"
                                     Height="{TemplateBinding ActualHeight}"
                                     Stroke="{StaticResource overlayBrush}"
                                     StrokeThickness="1">
                            </Ellipse>

                            <UIElement.RenderTransform>
                                <RotateTransform Angle="0"></RotateTransform>
                            </UIElement.RenderTransform>
                        </Grid>

                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsBusy"
                                 Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource rotateStoryboard}"
                                                 x:Name="rotateStoryboard_BeginStoryboard" />
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <RemoveStoryboard BeginStoryboardName="rotateStoryboard_BeginStoryboard" />
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</ResourceDictionary>
